package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.PositionSalaryChange;
import com.amsp.oa.oademo.service.PositionSalaryChangeService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/position-salary-change")
@Tag(name = "薪资职位变动管理")
@CrossOrigin
public class PositionSalaryChangeController {

    @Autowired
    private PositionSalaryChangeService positionSalaryChangeService;

    @GetMapping("/list")
    @Operation(summary = "获取薪资职位变动列表")
    public IPage<PositionSalaryChange> list(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String employeeNo,
            @RequestParam(required = false) String employeeName,
            @RequestParam(required = false) String originalDepartment,
            @RequestParam(required = false) String newDepartment,
            @RequestParam(required = false) String changeType,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate) {

        return positionSalaryChangeService.getPage(current, size, employeeNo, employeeName,
                originalDepartment, newDepartment, changeType, startDate, endDate);
    }

    @GetMapping("/{id}")
    @Operation(summary = "获取薪资职位变动详情")
    public PositionSalaryChange getById(@PathVariable Long id) {
        return positionSalaryChangeService.getById(id);
    }

    @PostMapping("/save")
    @Operation(summary = "保存薪资职位变动")
    public boolean save(@RequestBody PositionSalaryChange positionSalaryChange) {
        if (positionSalaryChange.getId() != null) {
            return positionSalaryChangeService.updateById(positionSalaryChange);
        }
        return positionSalaryChangeService.save(positionSalaryChange);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除薪资职位变动")
    public boolean delete(@PathVariable Long id) {
        return positionSalaryChangeService.removeById(id);
    }
}